package cn.xinyangtong.manager.interceptor;

import cn.xinyangtong.manager.controller.PageController;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author fengbo
 * @date 2017/7/25
 */
public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
        Object usreLogin = request.getSession().getAttribute(PageController.LOGIN_SESSION);
        if (usreLogin != null) {
            return true;
        }
        response.sendRedirect("/login");
        return false;
    }
}
